#include<iostream>
#include<string>
using namespace std;

class Solution {
public:
    int minimumOperations(string nums)
    {
        int n = nums.size();
        bool find0 = false;
        bool find5 = false;
        int count = 0;
        for (int i = n - 1; i >= 0; i--)
        {
            if (nums[i] == '0' || nums[i] == '5')
            {
                if (find0)
                    return n - i - 2;
                if (nums[i] == '0')
                    find0 = true;
                else if (nums[i] == '5')
                    find5 = true;
            }
            else if (nums[i] == '2' || nums[i] == '7')
            {
                if (find5)
                    return n - i - 2;
            }
        }
        if (find0)
            return n - 1;
        return n;
    }
};